package com.upic.serviceImpl;

import com.upic.po.College;
import com.upic.repository.CollegeRepository;
import com.upic.service.CollegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author YeTian
 * @date 2018/2/7/007
 */
@Service("collegeService")
public class CollegeServiceImpl implements CollegeService {

    @Autowired
    private CollegeRepository collegeRepository;

    @Override
    public College saveCollege(College college) {
        return collegeRepository.save(college);
    }

    @Override
    public String deleteCollege(long collegeId) {
        collegeRepository.delete(collegeId);
        return "SUCCESS";
    }

    @Override
    public Page<College> searchCollege(Pageable pageable) {
        return collegeRepository.findAll(pageable);
    }

    @Override
    public List<College> searchCollege() {
        return collegeRepository.findAll();
    }

    @Override
    public College findOne(long collegeId) {
        return collegeRepository.findOne(collegeId);
    }

    @Override
    public College updateCollege(College college) {
        return collegeRepository.saveAndFlush(college);
    }
}
